package com.ruoyi.teacher.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.AgeUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.teacher.domain.Teacher;
import com.ruoyi.teacher.domain.vo.BarVO;
import com.ruoyi.teacher.domain.vo.DataVO;
import com.ruoyi.teacher.domain.vo.PieVO;
import com.ruoyi.teacher.mapper.TeacherMapper;
import com.ruoyi.teacher.mapper.TransferMapper;
import com.ruoyi.teacher.service.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class TransferServiceImpl extends ServiceImpl<TransferMapper, Teacher> implements TransferService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    private TeacherServiceImpl teacherService;

    @Override
    public BarVO barVOList() {

        List<Teacher> teachers = teacherMapper.selectListNoParamaters();
        List<Integer> numbers = teacherService.selectCount();
        List<String> ageRanges = new ArrayList<>();
        BarVO barVO = new BarVO();
        for (Teacher teacher : teachers) {
            String birthDate = DateUtils.DateTimeToDate(teacher.getA0107());
            String ageFromBirthTime = AgeUtils.getAgeFromBirthTime(birthDate);
            ageRanges.add(ageFromBirthTime);
            barVO.setAgeRanges(ageRanges);
        }
        barVO.setNumbers(numbers);

        return barVO;
    }

    @Override
    public PieVO PieVOList() {
        PieVO pieVO = new PieVO();
        List<DataVO> data = new ArrayList<>();
        List<DataVO> degreeCount = teacherService.selectDegreeCount();
        for (DataVO degree : degreeCount) {
            data.add(degree);
        }
        pieVO.setData(data);
        return pieVO;
    }

    @Override
    public BarVO listTitleLevel() {

        BarVO barVO = new BarVO();
        List<Integer> titleCount = teacherService.selectTitleCount();
        barVO.setNumbers(titleCount);

        return barVO;
    }
}
